<template>
    <admin-frame>
        <header class="page-header">
            <div class="flex-fill">
                <el-breadcrumb separator="/">
                    <el-breadcrumb-item>会务管理</el-breadcrumb-item>
                    <el-breadcrumb-item>参会嘉宾</el-breadcrumb-item>
                    <el-breadcrumb-item>编辑信息</el-breadcrumb-item>
                </el-breadcrumb>
            </div>
            <div>
                <router-link to="/meeting/guest">
                    <el-button type="primary" size="small">返回列表</el-button>
                </router-link>
            </div>
        </header>
        <div class="mainframe-content">
            <div class="content-block">
                <table class="dsxui-formtable">
                    <tbody>
                    <tr>
                        <td>嘉宾照片</td>
                        <td>
                            <div class="w120" @click="showPicker=true">
                                <el-image :src="guest.image" fit="cover" class="img-110" v-if="guest.image"></el-image>
                                <div class="img-110 img-placeholder" v-else></div>
                            </div>
                        </td>
                    </tr>
                    <tr>
                        <td class="w60">嘉宾姓名</td>
                        <td>
                            <el-input size="medium" class="w300" v-model="guest.name"></el-input>
                        </td>
                    </tr>
                    <tr>
                        <td>联系电话</td>
                        <td>
                            <el-input size="medium" class="w300" v-model="guest.tel"></el-input>
                        </td>
                    </tr>
                    <tr>
                        <td>组织单位</td>
                        <td>
                            <el-input size="medium" class="w300" v-model="guest.organization"></el-input>
                        </td>
                    </tr>
                    <tr>
                        <td>邀请码</td>
                        <td>
                            <el-input size="medium" class="w300" v-model="guest.code"></el-input>
                        </td>
                    </tr>
                    <tr>
                        <td>会务分组</td>
                        <td>
                            <el-select
                                    size="medium"
                                    placeholder="请选择"
                                    v-model="guest.groupid"
                                    class="w300"
                            >
                                <el-option
                                        v-for="(group,index) in groups"
                                        :key="index"
                                        :label="group.title"
                                        :value="group.groupid"
                                />
                            </el-select>
                        </td>
                    </tr>
                    <tr>
                        <td>入住酒店</td>
                        <td>
                            <el-select
                                    size="medium"
                                    placeholder="请选择"
                                    v-model="guest.hotel_id"
                                    class="w300"
                            >
                                <el-option
                                        v-for="(hotel,index) in hotels"
                                        :key="index"
                                        :label="hotel.title"
                                        :value="hotel.id"
                                />
                            </el-select>
                        </td>
                    </tr>
                    </tbody>
                </table>
            </div>
        </div>
        <div class="h40"></div>
        <div class="edit-bottom">
            <el-button class="w100" @click="$router.go(-1)">取消</el-button>
            <el-button class="w100" type="primary" @click="handleSubmit">保存</el-button>
        </div>
        <image-picker v-model="showPicker" @confirm="handlePickedImage"></image-picker>
    </admin-frame>
</template>

<script>
    import AdminFrame from "../common/AdminFrame";
    import KindEditor from "../../lib/KindEditor";

    export default {
        name: "LiveEdit",
        components: {
            AdminFrame,
            KindEditor,
        },
        data() {
            return {
                id: 0,
                guest: {},
                groups: [],
                hotels: [],
                showPicker: false
            }
        },
        mounted() {
            this.id = this.$route.query.id || 0;
            if (this.id) this.fetchData();
            this.$get('/admin/meeting/group/getall').then(response=>{
                this.groups = response.data.items;
            });
            this.$get('/admin/meeting/hotel/batchget?count=100').then(response=>{
                this.hotels = response.data.items;
            });
        },
        methods: {
            fetchData() {
                this.$get('/admin/meeting/guest/get?id=' + this.id).then(response => {
                    this.guest = response.data.guest;
                });
            },
            handlePickedImage(data) {
                this.guest.image = data.image;
            },
            handleSubmit() {
                const guest = this.guest;
                if (!guest.name) {
                    this.$showToast('请填写嘉宾姓名');
                    return false;
                }

                if (!guest.tel) {
                    this.$showToast('请填写嘉宾电话');
                    return false;
                }

                const id = this.id;
                this.$post('/admin/meeting/guest/save', {id, guest}).then(response => {
                    this.$showToast('信息保存成功!', () => this.$router.go(0));
                });
            }
        }
    }
</script>

<style scoped>

</style>
